/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Chen weihan <csq-3@163.com>
 * @since : 2014年08月11日 星期一 10时07分06秒
 * @filename : seams/modules/sea-modules/anchor/anchor.js
 * @version : 
 * @description : 
 */
define(function(require, exports, module) {

   var $ = require('zepto');

   var router = {
          
          hashChangeAnchor : function() {
              console.log('changeAnchor');
              this.router();
          },

          switchPage : function() {

          },

          getAnchor : function(item) {
              var arr = window.location.hash.match(new RegExp("[\#\&]" + item + "=([^\&]*)(\&?)","i")),
                  val =  arr ? arr[1] : 'index';
              return val;
          },

          router : function() {
	      var name = this.getAnchor('name'),
                  tabNum = this.getAnchor('tab'),
                  type = this.getAnchor('type');
               
               //require只能使用字符串直接量，路由只能手工分发
               $('.page').hide();

               switch(name) {
                  case 'index' : 
                        require.async('./index',function(index){
			   var s = new index();
			       s.render();                           
		        });
                  break;

                  case 'joinus':
                        require.async('./joinus',function(joinus){
                           var s = new joinus();
                               s.render(tabNum); 
                        });
                  break;
               };
          }
       };

       router.hashChangeAnchor();
       window.onhashchange = function(){router.hashChangeAnchor()};
       module.exports = router;
});
